package com.wz.dhs.model;


import com.wz.dhs.model.common.PageInfo;
import com.wz.dhs.model.common.Search;

import java.util.ArrayList;
import java.util.List;

/**
 * @description: 分页返回
 * @author: xia
 * @since: 2021/8/26
 **/
public class PageHandler {

    public static <T, K extends Search> PageInfo<T> returnPage(List<T> data, K param, Long total){
        PageInfo<T> pageInfo = new PageInfo<>();
        pageInfo.setTotal(total);
        pageInfo.setPageNum(param.getPageNum());
        pageInfo.setPageSize(param.getPageSize());
        pageInfo.setData(data);
        return pageInfo;
    }

    public static <T, K extends Search> PageInfo<T> returnPage(List<T> data, int pageNum, int pageSize, Long total){
        PageInfo<T> pageInfo = new PageInfo<>();
        pageInfo.setTotal(total);
        pageInfo.setPageNum(pageNum);
        pageInfo.setPageSize(pageSize);
        pageInfo.setData(data);
        return pageInfo;
    }

    public static <K extends  Search> PageInfo returnNullPage(K param){
        PageInfo pageInfo = new PageInfo<>();
        pageInfo.setTotal(0L);
        pageInfo.setPageNum(param.getPageNum());
        pageInfo.setPageSize(param.getPageSize());
        pageInfo.setData(new ArrayList());
        return pageInfo;
    }

}
